﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using InfoJetSoft.Service.Util;

//CID 0875 //2011.05.04 //Begin
namespace InfoJetSoft.Service.XPath.Exprs
{
    public class BindingTestVisitor : IExprVisitor
    {
        private bool isExplicit = true;
        private bool isMutable = false;
        private List<string> mutableFuncNames = new List<string>();

        public bool IsExplicit
        {
            get
            {
                return this.isExplicit;
            }
        }

        public bool IsMutable
        {
            get
            {
                return this.isMutable;
            }
        }

        public BindingTestVisitor(XmlNamespaceManager nsResolver)
        {
            string mathPrefix = nsResolver.LookupPrefix(JetConstant.URI_XDMATH);
            string datePrefix = nsResolver.LookupPrefix(JetConstant.URI_XDDATE);
            string userPrefix = nsResolver.LookupPrefix(JetConstant.URI_XDXDOC);
            this.mutableFuncNames.Add(NamespaceUtil.toFullName(mathPrefix, "Eval"));
            this.mutableFuncNames.Add(NamespaceUtil.toFullName(datePrefix, "Today"));
            this.mutableFuncNames.Add(NamespaceUtil.toFullName(datePrefix, "Now"));
            this.mutableFuncNames.Add(NamespaceUtil.toFullName(datePrefix, "AddDays"));
            this.mutableFuncNames.Add(NamespaceUtil.toFullName(datePrefix, "AddSeconds"));
            this.mutableFuncNames.Add(NamespaceUtil.toFullName(userPrefix, "getUserName"));
            this.Reset();
        }

        public void SetExplicit(bool isExplicit)
        {
            this.isExplicit = isExplicit;
        }

        public void OnFunctionName(string functionName)
        {
            if (this.mutableFuncNames.Contains(functionName))
            {
                this.isMutable = true;
            }
        }

        public void Reset()
        { 
            this.isExplicit = true;
            this.isMutable = false;
        }
    }
}
//CID 0875 //2011.05.04 //End